<?php
declare (strict_types=1);

namespace app\admin\service;

use app\admin\model\RoleModel;


class RoleService extends \think\Service
{
    /**
     * 注册服务
     *
     * @return mixed
     */
    public function register()
    {
        //
    }

    /**
     * 执行服务
     *
     * @return mixed
     */
    public function boot()
    {
        //
    }

    /**
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function index($params): \think\response\Json
    {
        $query = RoleModel::query();
        $res = $query->page($params['pageNum'], $params['pageSize'])->select();
        return successMsg(data: makePaginate($res , $query->count() , $params));
    }

    /**
     * @param $params
     * @return \think\response\Json
     */
    public function create($params): \think\response\Json
    {
        $res = RoleModel::create($params);
        return successMsg(data: $res);
    }

    /**
     * @param $id
     * @param $params
     * @return \think\response\Json
     */
    public function update($id , $params): \think\response\Json
    {
        $res = RoleModel::update($params , ['id' => $id]);
        return successMsg(data: $res);
    }

    /**
     * @param $id
     * @return array|mixed
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function read($id): mixed
    {
        return RoleModel::find($id);
    }
}
